package com.hualan.sfzy.controller.consult;


import com.hualan.sfzy.constant.CommonConstant;
import com.hualan.sfzy.model.entity.Consult;
import com.hualan.sfzy.model.entity.ConsultExpertise;
import com.hualan.sfzy.service.impl.consult.ConsultExpertiseServiceImpl;
import com.hualan.sfzy.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/consultExpertise")

// 咨询师擅长领域表中间表服务实现类
public class ConsultExpertiseController {
    @Autowired
    private ConsultExpertiseServiceImpl service;

    @PostMapping
    // 添加咨询师擅长领域表中间表
    /*
     * 前端应该传递参数为：
     * [
     *   {
     *     "consultid": 5,
     *     "expertiseid": 2
     *   },
     *   {
     *     "consultid": 5,
     *     "expertiseid": 3
     *   }
     * ]
     */
    public Result add(@RequestBody List<ConsultExpertise> list) {
        return service.addPro(list) > 0 ? Result.success() : Result.error();
    }

    @PutMapping
    // 修改咨询师擅长领域表中间表
    public Result edit(@RequestBody ConsultExpertise entity) {
        return service.edit(entity) > 0 ? Result.success() : Result.error();
    }

    @DeleteMapping
    // 批量删除咨询师擅长领域表中间表
    public Result removeBatch(Integer[] ids) {
        return service.removeBatch(ids) > 0 ? Result.success() : Result.error();
    }

    @DeleteMapping("/{id}")
    // 根据 id 删除咨询师擅长领域表中间表
    public Result remove(@PathVariable("id") Integer id) {
        return service.remove(id) > 0 ? Result.success() : Result.error();
    }

    @GetMapping
    // 查找全部咨询师擅长领域表中间表
    public Result find() {
        return Result.success(service.find());
    }

    @GetMapping("/{id}")
    // 根据 id 获取咨询师擅长领域表中间表
    public Result findById(@PathVariable("id") Integer id) {
        return Result.success(service.findById(id));
    }

    @GetMapping("/page")
    // 分页查询咨询师擅长领域表中间表
    /*  前端请求地址为：http://localhost:8080/consultExpertise
        示例：
    *       /page?consult.consultName=张
    * */
    public Result findPro(
            @RequestParam(value = CommonConstant.PAGE_NUM, required = false, defaultValue = CommonConstant.PAGE_NUM_DEFAULT) Integer pageNum,
            @RequestParam(value = CommonConstant.PAGE_SIZE, required = false, defaultValue = CommonConstant.PAGE_SIZE_DEFAULT) Integer pageSize,
           ConsultExpertise entity) {
        return Result.success(service.findPage(pageNum, pageSize,entity));
    }

    @GetMapping("/selectConsultExpert")
    public Result selectConsultExpert() {
        return Result.success(service.selectConsultExpert());
    }
    @GetMapping("/selectConsultExpert/{id}")
    public Result selectConsultExpertId(@PathVariable("id") Integer id) {
        return Result.success(service.selectConsultExpertId(id));
    }


}
